home *** CD-ROM | disk | FTP | other *** search
/ Mission 3 / Mission 3.zip / Mission 3.iso / texte / qed / src / dd.c < prev    next >
C/C++ Source or Header  |  1998-10-11  |  6KB  |  324 lines

  1. #include <limits.h>
  2.  
  3. #include "global.h"
  4. #include "comm.h"
  5. #include "dd.h"
  6. #include "edit.h"
  7. #include "find.h"
  8. #include "icon.h"
  9. #include "projekt.h"
  10. #include "rsc.h"
  11. #include "text.h"
  12. #include "window.h"
  13.  
  14.  
  15. /* exportierte Variablen *****************************************************/
  16. PATH    drag_filename;        /* Dateiname/Pfad wurde gedragged */
  17. char    *drag_data;            /* Daten wurden gedragged */
  18. long    drag_data_size;    /* Die Länge der Daten */
  19.  
  20.  
  21. /* DD Empfang ****************************************************************/
  22.  
  23. static int parse_ARGS(char *str)
  24. {
  25.     int        cnt = 1;
  26.     char     *c = str;
  27.     bool    in_quote = FALSE;
  28.  
  29.     while (*c)
  30.     {
  31.         switch (*c)
  32.         {
  33.             case ' ' :
  34.                 if (!in_quote)
  35.                 {
  36.                     *c = '\0';
  37.                     cnt++;
  38.                 }
  39.                 break;
  40.             case '\'' :
  41.                 strcpy(c, c + 1);
  42.                 if (!in_quote)
  43.                     in_quote = TRUE;
  44.                 else
  45.                 {
  46.                     if (*c != '\'')
  47.                     {
  48.                         in_quote = FALSE;
  49.                         *c = 0;
  50.                         if (c[1])
  51.                             cnt++;
  52.                     }
  53.                 }
  54.                 break;
  55.             default:
  56.                 break;
  57.         } /* switch */
  58.         c += 1;
  59.     } /* while */
  60.     return cnt;
  61. }
  62.  
  63.  
  64. static int rel_path(char *path, bool cs, char *sub_path)
  65. {
  66.     int    l;
  67.     char    p1[256];
  68.     
  69.     split_filename(path, p1, NULL);
  70.     l = (int)strlen(p1);
  71.     if (cs)
  72.     {
  73.         if (strncmp(p1, sub_path, l) == 0)
  74.             return l;
  75.     }
  76.     else
  77.     {
  78.         if (strnicmp(p1, sub_path, l) == 0)
  79.             return l;
  80.     }
  81.     return 0;
  82. }
  83.  
  84. /* Werte vom Popup */
  85. #define DRAG_PATHNAME    0
  86. #define DRAG_PATH            1
  87. #define DRAG_NAME            2
  88. #define DRAG_RELPATH        3
  89. #define DRAG_INHALT        4
  90.  
  91. static void insert(WINDOWP w, int mode, bool shift, char *filename)
  92. {
  93.     int    icon;
  94.  
  95.     make_normalpath(filename);
  96.  
  97.     if (w->class == CLASS_PROJEKT)
  98.     {
  99.         strcpy(drag_filename, filename);
  100.         if (filename[strlen(filename) - 1] == '\\')            /* Pfad */
  101.             icon_drag(w->handle, DRAGDROP_PATH);                /*  -> Datei suchen */
  102.         else                                                                /* Datei */
  103.             icon_drag(w->handle, DRAGDROP_FILE);                /*  -> einfügen */
  104.     }
  105.     else
  106.     {
  107.         if (filename[strlen(filename) - 1] == '\\')            /* Pfad */
  108.             mode = DRAG_PATHNAME;
  109.  
  110.         if (mode == DRAGDROP_PATH)
  111.         {
  112.             if (!shift && filematch(filename, "*.QPJ", -1))
  113.                 icon = load_projekt(filename);
  114.             else
  115.                 icon = load_edit(filename, FALSE);
  116.             if (icon > 0)
  117.                 send_dhst(filename);
  118.         }
  119.         else
  120.         {
  121.             TEXTP    t_ptr;
  122.             int    i;
  123.  
  124.             switch (mode)
  125.             {
  126.                 case DRAG_PATHNAME :
  127.                     strcpy(drag_filename, filename);
  128.                     icon_drag(w->handle, DRAGDROP_PATH);
  129.                     break;
  130.     
  131.                 case DRAG_PATH :
  132.                     split_filename(filename, drag_filename, NULL);
  133.                     icon_drag(w->handle, DRAGDROP_PATH);
  134.                     break;
  135.                     
  136.                 case DRAG_NAME :
  137.                     split_filename(filename, NULL, drag_filename);
  138.                     icon_drag(w->handle, DRAGDROP_PATH);
  139.                     break;
  140.     
  141.                 case DRAG_RELPATH :
  142.                     t_ptr = get_text(w->handle);
  143.                     if (t_ptr && !t_ptr->namenlos)
  144.                     {
  145.                         i = rel_path(t_ptr->filename, (t_ptr->filesys == FULL_CASE), filename);
  146.                         strcpy(drag_filename, filename + i);
  147.                         icon_drag(w->handle, DRAGDROP_PATH);
  148.                     }
  149.                     break;
  150.                     
  151.                 case DRAG_INHALT :
  152.                     strcpy(drag_filename, filename);
  153.                     icon_drag(w->handle, DRAGDROP_FILE);
  154.                     break;
  155.  
  156.                 default:
  157.                     debug("dd.c,insert: unbekanter mode %d\n", mode);
  158.                     break;
  159.             }
  160.         }
  161.     }
  162. }
  163.  
  164.  
  165. static void parse(char *cmdline, WINDOWP w, int kstate)
  166. {
  167.     int    comps = parse_ARGS(cmdline);
  168.     char    *c = cmdline;
  169.     int    i, mode = DRAGDROP_PATH;
  170.     bool    shift;
  171.     
  172.     shift = (kstate & (K_LSHIFT|K_RSHIFT));
  173.     
  174.     if (w->class == CLASS_EDIT && (kstate & K_ALT))
  175.     {
  176.         i = handle_popup(NULL, 0, popups, DRAGPOP, POP_OPEN);
  177.         switch (i)
  178.         {
  179.             case DPALL :
  180.                 mode = DRAG_PATHNAME;
  181.                 break;
  182.  
  183.             case DPPATH :
  184.                 mode = DRAG_PATH;
  185.                 break;
  186.                 
  187.             case DPNAME :
  188.                 mode = DRAG_NAME;
  189.                 break;
  190.  
  191.             case DPRELPATH :
  192.                 mode = DRAG_RELPATH;
  193.                 break;
  194.  
  195.             case DPINHALT :
  196.                 mode = DRAG_INHALT;
  197.                 break;
  198.  
  199.             default:
  200.                 Bconout(2, 7);
  201.                 return;
  202.         }
  203.     }
  204.  
  205.     drag_data_size = comps;            /* Anzahl der ARGS merken */
  206.     while (comps - 1)
  207.     {
  208.         insert(w, mode, shift, c);
  209.         c += strlen(c) +1;
  210.         comps--;
  211.     }
  212.     insert(w, mode, shift, c);
  213. }
  214.  
  215. void    handle_dd(int *msg)
  216. {
  217.     WINDOWP     w_dest = get_window(msg[3]);
  218.     int        fd;
  219.     long        size;
  220.     char         ext[5],
  221.                 fname[PATH_MAX],
  222.                 ourexts[DD_EXTSIZE] = "ARGS.TXT";
  223.  
  224.     if (w_dest != NULL)
  225.     {
  226.         fd = (int)dd_open(msg[7], ourexts);
  227.         if (fd < 0)
  228.             return ;
  229.  
  230.         do
  231.         {
  232.             if (!dd_rtry(fd, fname, ext, &size))
  233.             {
  234.                 dd_close(fd);
  235.                 return;
  236.             }
  237.             if (!strncmp(ext, "ARGS", 4))
  238.             {
  239.                 char    *cmdline = malloc(size +1);
  240.  
  241.                 if (!cmdline)
  242.                 {
  243.                     dd_reply(fd, DD_LEN);
  244.                     continue;
  245.                 }
  246.                 dd_reply(fd, DD_OK);
  247.                 Fread((int) fd, size, cmdline);
  248.                 dd_close(fd);
  249.                 cmdline[size] = 0;
  250.                 parse(cmdline, w_dest, msg[6]);
  251.                 free(cmdline);
  252.                 drag_data_size = 0;
  253.                 return ;
  254.             }
  255.             if (strncmp(ext, ".TXT", 4) == 0 )
  256.             {
  257.                 drag_data = malloc(size + 1);
  258.                 /* ^^ wird nach dem Einfügen in edit.c wieder freigegeben! */
  259.                 drag_data_size = size;
  260.                 if (drag_data == NULL)
  261.                 {
  262.                     dd_reply(fd, DD_LEN);
  263.                     continue;
  264.                 }
  265.                 dd_reply(fd, DD_OK);
  266.                 Fread((int) fd, drag_data_size, drag_data);
  267.                 dd_close(fd);
  268.                 drag_data[drag_data_size] = 0;
  269.                 icon_drag(w_dest->handle, DRAGDROP_DATA);
  270.                 return ;
  271.             }
  272.         }
  273.         while (dd_reply(fd, DD_EXT));
  274.     }
  275. }
  276.  
  277.  
  278. void    handle_avdd(int win_handle, int kstate, char *arg)
  279. {
  280.     WINDOWP     w_dest = get_window(win_handle);
  281.     char        *cmdline;
  282.     
  283.     if (w_dest != NULL)
  284.     {
  285.         cmdline = (char *) malloc(strlen(arg));
  286.         strcpy(cmdline, arg);
  287.         parse(cmdline, w_dest, kstate);
  288.         free(cmdline);
  289.     }
  290. }
  291.  
  292. /* DD Senden *****************************************************************/
  293.  
  294. #if 0
  295.  
  296. void send_dd(int wh, MOUSEDATA *mouse, int data_type)
  297. {
  298.     int        pipe, app, d;
  299.     ulong        types[DD_NUMEXTS];
  300.     long        ret;
  301.     
  302.     wind_get(wh, WF_OWNER, &app, &d, &d, &d);
  303.     pipe = dd_create(app, wh, mk, types);
  304.     if (pipe > 0)
  305.     {
  306.         switch (data_type)
  307.         {
  308.             case DRAGDROP_FILE :
  309.                 break;
  310.             case DRAGDROP_PATH :
  311.                 if (dd_stry(pipe, 'ARGS', "ARGS.TXT", strlen(drag_filename) + 1) == DD_OK)
  312.                 {
  313.                     ret = Fwrite(pipe, strlen(drag_filename) + 1, drag_filename);
  314.                     Fclose(pipe);
  315. Debug("qed: D&D to Win %d, App %d\n", wh, app);
  316.                 }
  317.                 break;
  318.             case DRAGDROP_DATA :
  319.                 break;
  320.         }
  321.     }
  322. }
  323. #endif
  324.